#pragma once

#include "jni.h"
#include <stdio.h>

#define MARK_UNSUPPORTED(env, clazz)  env->ThrowNew(clazz, "This native api is unsupported!")

#define CHECK_FIELD(field, err_label, env, clazz, class_name, field_name)    \
{\
	if(!field)\
	{\
		char buffer[256];\
		snprintf(buffer, sizeof(buffer), "Can't find filed(%s) of class(%s)!", field_name, class_name);\
		env->ThrowNew(clazz, buffer);\
		goto err_label;\
	}\
}

#define CHECK_GET_NULL(obj, err_label)	\
{\
	if(!obj)\
	{\
		goto err_label;\
	}\
}

#define THROW_EXCEPTION2(err_label, fmt, ...) \
{\
	char buffer[256];\
	char *class_name = "java/lang/Exception";\
	jclass ex_class;\
	ex_class = env->FindClass(class_name);\
	if (ex_class == NULL) \
	{\
		goto err_label; \
	}\
	snprintf(buffer, sizeof(buffer), fmt, ##__VA_ARGS__);\
	env->ThrowNew(ex_class, buffer);\
	goto err_label;\
}